package com.project.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.EmailBean;
import com.project.bean.InBoxBean;
import com.project.mapper.IEmailMapper;
import com.project.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Arrays;

@Service
@Transactional
public class EmailServiceImp implements IEmailService  {
    @Autowired
    private IEmailMapper mapper;
    @Override
    public void add(EmailBean emailBean, int[] idArray, String[] strNameArray) {
        String strName= Arrays.toString(strNameArray);
        String strName2=strName.substring(1,Arrays.toString(strNameArray).length()-1);
        mapper.add(emailBean,strName2);
        mapper.addInBox(emailBean.getEmailId(),idArray);
    }

    @Override
    public PageInfo<EmailBean> cutPageByItem(Integer pageNum, Integer userId, String title, LocalDate startTim, LocalDate endTim) {
        PageHelper.startPage(pageNum,2);
        PageInfo<EmailBean> pg = PageInfo.of(mapper.cutPageByItem(userId,title,startTim,endTim));
        return pg;
    }

    @Override
    public EmailBean findById(Integer emailId) {
        EmailBean emailBean =mapper.findById(emailId);
        return emailBean;
    }

    @Override
    public void del(Integer emailId) {
        mapper.del(emailId);
    }
}
